<#assign pageName="修改授权信息">
<@override name="head-styles">
    <style>
        .layui-form .layui-form-label {
            width: 150px;
        }
        .layui-form .layui-input-block {
            margin-left: 180px;
        }
    </style>
</@override>
<@override name="page-content">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>${pageName}</legend>
    </fieldset>
    <form class="layui-form padding-10" lay-filter="formOauthClientEdit">
        <#if errorMsg?has_content>
            <div class="align-center" style="color:red;font-weight:bold;">${errorMsg}</div>
            <@ctrl.FormAction buttons=['back'] backURL="../manage" class="align-center margin-10-0"/>
        <#else>
             <@ctrl.Textbox path="oauthClientDetails.clientId" labelText="客户端ID" attributes="readonly='readonly'" required="required"/>
             <@ctrl.Textbox path="oauthClientDetails.clientName" labelText="客户端名称" required="required"/>
             <@ctrl.Textbox path="oauthClientDetails.clientSecret" labelText="客户端秘钥" attributes="readonly='readonly'" required="required">
             <button id="reSecret" class="btn btn-sm btn-info" type="button">
                 <i class="ace-icon fa fa-key bigger-110"></i>
                 重新生成密钥
             </button>
             </@ctrl.Textbox>
             <@ctrl.Textarea path="oauthClientDetails.clientIntro" labelText="应用简介"/>
             <@ctrl.Textbox path="oauthClientDetails.clientUrl" labelText="应用官网"/>
             <@ctrl.Textbox path="oauthClientDetails.username" labelText="客户名称" required="required"/>
             <@ctrl.Textbox path="oauthClientDetails.linkman" labelText="联系用户" required="required"/>
             <@ctrl.Textbox path="oauthClientDetails.linktel" labelText="联系电话" required="required"/>
             <@ctrl.Hidden path="oauthClientDetails.resourceIds" value="auth-resource"/>
             <@ctrl.CheckboxList path="oauthClientDetails.authorizedGrantTypes" labelText="授权类型" options = [{'0':'客户端模式[client_credentials]','1':'client_credentials'},{'0':'授权码模式[authorization_code]','1':'authorization_code'},{'0':'用户密码模式[password]','1':'password'},{'0':'刷新Token[refresh_token]','1':'refresh_token'}]/>
             <@ctrl.Textbox path="oauthClientDetails.webServerRedirectUri" labelText="客户端的重定向URI(授权码模式)"/>
             <@ctrl.Textbox path="oauthClientDetails.scope" value="read,write" labelText="授权范围" required="true"/>
             <@ctrl.Textbox path="oauthClientDetails.accessTokenValidity" labelText="accessToken有效期(秒)" value="43200"/>
             <@ctrl.Textbox path="oauthClientDetails.refreshTokenValidity" labelText="refreshToken有效期(秒)"  value="86400"/>
             <@ctrl.Hidden path="oauthClientDetails.authorities" value="ROLE_ANONYMOUS" />
             <@ctrl.Textbox path="oauthClientDetails.accessTokenValidity" labelText="accessToken有效期(秒)">默认有效期是12小时，60 * 60 * 12 = 43200</@ctrl.Textbox>
             <@ctrl.Textbox path="oauthClientDetails.refreshTokenValidity" labelText="refreshToken有效期(秒)">默认有效期是24小时，60 * 60 * 24 = 86400</@ctrl.Textbox>
             <@ctrl.Hidden path="oauthClientDetails.archived" />
             <@ctrl.Hidden path="oauthClientDetails.trusted" />
             <@ctrl.Hidden path="oauthClientDetails.autoApprove" />
             <@ctrl.Textarea path="oauthClientDetails.additionalInformation" labelText="IP白名单">多个IP以逗号分隔，例如：192.168.0.1,192.168.0.2</@ctrl.Textarea>
             <@ctrl.Hidden path="oauthClientDetails.createTime"/>
             <@ctrl.FormAction backURL="manage" backURL="../manage"/>
        </#if>
    </form>
</@override>
<@override name="page-scripts">
    <script>
        $('#reSecret').click(function(e){ 
            $('#clientSecret').val($.ajax({url:"${contextPath}/oauth/oauthclient/createSecret",async:false}).responseText);
        });
        
        $(function(){
            layui.use(['form','layer', 'jquery'], function(){
                var form = layui.form;
                var layer=layui.layer;
                $=layui.jquery;
                //监听提交
                form.on('submit(submit)', function(data){
                    var checkedGrantType =[]; 
                    var checkedRoles =[]; 
                    $('input[name="authorizedGrantTypes"]:checked').each(function(index, item){ 
                        checkedGrantType.push($(this).val()); 
                    });
                    $('input[name="authorities"]:checked').each(function(index, item){ 
                        checkedRoles.push($(this).val()); 
                    });
                    data.field.authorizedGrantTypes = checkedGrantType;
                    data.field.authorities = checkedRoles;
                    submitData(data.field, '${contextPath}/oauth/oauthclient/edit', function(){location.href="${contextPath}/oauth/oauthclient/manage";});
                    return false;
                });
            })
        })
    </script>  
</@override>
<@extends name="/layout/basepage.html"/> 